<template>
  <div class="user-container">
    <div class="info-user">
      <van-image
        round
        fit="cover"
        width="64"
        height="64"
        :src="userInfo.photo"
      />
      <h2>
        {{ userInfo.name }}<br /><van-tag color="#fff" text-color="#0098fa">{{
          userInfo.birthday
        }}</van-tag>
      </h2>
    </div>
    <van-row class="user-nav">
      <van-col span="8"
        ><van-icon name="newspaper-o" color="#5facff" /><span
          >我的作品</span
        ></van-col
      >
      <van-col span="8"
        ><van-icon name="star-o" color="#ff1218" /><span
          >我的收藏</span
        ></van-col
      >
      <van-col span="8"
        ><van-icon name="tosend" color="#ffa600" /><span
          >阅读历史</span
        ></van-col
      >
    </van-row>
    <van-cell-group class="cell">
      <van-cell title="编辑资料" icon="edit" is-link @click="$router.push('/edit')"/>
      <van-cell title="小智同学" icon="chat-o" is-link @click="$router.push('student')"/>
      <van-cell title="系统设置" icon="setting-o" is-link />
      <van-cell title="退出登录" icon="warning-o" is-link @click="logout" />
    </van-cell-group>
  </div>
</template>

<script>
import { getUserInfo } from './user.js'
import {removeToken} from '@/utils/token.js'
export default {
  name: 'user',
  data () {
    return {
      userInfo: {}
    }
  },
  created () {
    getUserInfo().then(res => {
      console.log(res)
      this.userInfo = res.data.data
      this.$store.commit('updateUserInfo',res.data.data)
    })
  },
  methods: {
    logout () {
      this.$dialog
        .confirm({
          title: '提示',
          message: '确定要退出登录吗'
        })
        .then(() => {
          removeToken()
          this.userInfo={}
          this.$router.push('/login')
        }).catch(()=>{
          
        })
    }
  }
}
</script>

<style scoped lang="less">
.user-container {
  .info-user {
    height: 100px;
    background-color: #0098fa;
    display: flex;
    align-items: center;
    .van-image {
      padding: 0 10px;
    }
    h2 {
      color: #fff;
      font-size: 18px;
      font-weight: normal;
    }
  }
  .user-nav {
    margin: 10px 0;
    text-align: center;
    // font-size: 16px;
    span {
      display: block;
      font-size: 16px;
    }
  }
}
</style>
